<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <title>01使用选择器在页面插入文字和图像</title>
    <script src="../jquery-2.2.0.js"></script>
    <script src="../main.js"></script>
    <link rel="stylesheet" href="../common.css">
    <style>
        #text h2:before{
            content: "COLUMN";
            color: #fff;
            background-color: orange;
            font-family: "Comic Sans MS",sans-serif;
            padding:1px 5px;
            margin-right: 10px;
        }
        #text h2.egNone:before{
            content: none;
        }
        #text h2.egNormal:before{
            content: normal;
        }
        
        #img h2:after{
            content: url("new.png");
            width: 20px;
        }
        #img h2:nth-child(3):after{
            content: normal;
        }
        #img h2:nth-child(3){
            height: 3em;
            background: url("new.png") no-repeat;
            padding:30px 0 0 80px;
        }

        #alt img:before{
            content: attr(alt);
            display: block;
            text-align: center;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<h1>2-1使用选择器在页面插入文字和图像</h1>

<h3>给所有的h2前面插入文本，当content的值分别为none和normal时表现一样，即不插入内容</h3>
<code>
    #text h2:before{
        content: "COLUMN";
        color: #fff;
        background-color: orange;
        font-family: "Comic Sans MS",sans-serif;
        padding:1px 5px;
        margin-right: 10px;
    }
    #text h2.egNone:before{
        content: none;
    }
    #text h2.egNormal:before{
        content: normal;
    }
</code>
<section id="text">
    <h2>这是h2标题</h2>
    <h2>这是h2标题</h2>
    <h2 class="egNone">这是h2标题<code>class="egNone"</code></h2>
    <h2 class="egNormal">这是h2标题<code>class="egNormal"</code></h2>
    <h2>这是h2标题</h2>
</section>
<h3>插入图像，标题C前面的图是背景图片，打印时可选择是否显示</h3>
<code>
    #img h2:after{
        content: url("new.png");
        width: 20px;
    }
    #img h2:nth-child(3):after{
        content: normal;
    }
    #img h2:nth-child(3){
        height: 3em;
        background: url("new.png") no-repeat;
        padding:30px 0 0 80px;
    }

</code>
<section id="img">
    <h2>标题A</h2>
    <h2>标题B</h2>
    <h2>标题C</h2>
    <h2>标题D</h2>
    <h2>标题E</h2>
</section>
<h3>将alt值作为图像标题显示出来<span>(貌似浏览器对这个功能支持的不好)</span></h3>
<code>
    #alt img:before{
        content: attr(alt);
        display: block;
        text-align: center;
        margin-top: 10px;
    }

</code>
<section id="alt">
    <img src="kangaroo.jpg" alt="袋鼠每天拥抱救命恩人">
</section>
</body>
</html>